<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<style type="text/css" media="all">
     body{margin:0;font-size:12px;background-color:#efefef;text-align:center;}
</style>
<script language="javascript" type="text/javascript" src="/resource/plugins/fckeditor/fckeditor.js?time=1"></script>
<script language="JavaScript" type="text/javascript">
<!--
	try{
        oEditor = window.parent.InnerDialogLoaded();
        window.parent.SetOkButton(true);
	 }catch(e){}

	 var channelid=parent.parent.document.getElementById("channelId").value;
	 var articleid=parent.parent.document.getElementById("articleId").value;
	 
	uploadImagCheck = function(){
	 this.AllowExt=".gif,.jpg,.jpeg,.png";
	 this.ImgObj=new Image(); 
	 this.FileExt=""; 
	 this.ErrMsg="";
	}
 
   uploadImagCheck.prototype.CheckExt = function(obj){
	   this.ErrMsg=""; 
	   this.ImgObj.src=obj.value;
		if(obj.value=="") 
		{ 
		   this.ErrMsg="\n请选择一个文件";    
		} 
		else 
		{   
		  this.FileExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase(); 
		  if(this.AllowExt!='' && this.AllowExt.indexOf(this.FileExt)==-1)//判断文件类型是否允许上传 
		  { 
		   obj.value = ""; 
		   this.ErrMsg="\n文件类型非法,请上传 "+this.AllowExt+" 类型的文件,当前文件类型为"+this.FileExt;   
		  } 
		 }
		 if(this.ErrMsg!="") 
		 { 
		  this.ShowMsg(this.ErrMsg);
		  $$("upload_btn").disabled=true;
		  return false; 
		 }
		  $$("upload_btn").disabled=false;
		 return true;
	}
  
	uploadImagCheck.prototype.ShowMsg = function(message){
	   alert(message);  
	}

	function $$(obj){
       return document.getElementById(obj);
    }

    function isNullValue(obj){
      return $$(obj).value==null||$$(obj).value==""?true:false;
    }
 
	function checkImag(obj) 
	{ 
	 var image=new uploadImagCheck(); 
	 image.CheckExt(obj); 
	} 
   
	//隐藏按钮
	function change(o){
		if($$("upload_img_id").value!=""){
			$$("upload_btn").disabled=false;
		}else{
			$$("upload_btn").disabled=true;
		}
		//gif,jpg,jpeg,png 大小：200kb
	}

	//上传
	function up(){
	
        if(isNullValue("upload_img_id")){
           alert("未选择上传图片!");
           return;
        }
		
        var flag = $$("add_flag")
        
        var radios = document.getElementsByName("operator_flag");
        var oValue;
        
        for(var i=0;i<radios.length;i++){
             if(radios[i].checked)
             {
                oValue = radios[i].value; 
             }
        }

        if(oValue==2){
        	if(isNullValue("upload_mask")){
                alert("水印图不能为空");
                return;   
              }
         }
        
		$$("upload_btn").disabled=true;

		if($$("up_state").value=="本地"){
			document.form1.place.value="local";
			document.form1.articleId.value=articleid;
			document.form1.pictitle.value="hahahah";
		}else if($$("up_state").value=="网络"){
			document.form1.place.value="net";
		}

		var formObj =$$("upload_form");
		
		formObj.action="/article/uploadPicInUEditor.do";
		formObj.submit();
	}

	//后台提示信息
	function check_img(state,file_name){
		$$("message").innerText=state;
		$$("file_name").innerHTML=file_name;
	}

	function check_mask(state){
		$$("message").innerText=state;
    }

	//上传成功,点击确认
	function Ok(){
		var _obj=$$("file_name");
		if(_obj.innerHTML!=""){
			oEditor.FCK.InsertHtml('<p style="text-align:center"><img src="'+_obj.innerHTML+'"></p>');
		}
		return true;
	 }
	 
	 
	//设置cookie   
  function setCookie(name,value)   
  {   
    var Days = 30; //此 cookie 将被保存 30 天   
    var exp  = new Date();  //new Date("December 31, 9998");   
    exp.setTime(exp.getTime() + Days*24*60*60*1000);   
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();   
  }  
	 
	//取cookies函数    
  function getCookie(name)          
  {   
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));   
    if(arr != null) return unescape(arr[2]);   
        
    return null;   
  }   
  
 //删除cookie   
  function delCookie(name)   
  {   
    var exp = new Date();   
    exp.setTime(exp.getTime() - 1);   
    var cval=getCookie(name);   
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();   
  }
  
  
  function addCookie(){
  	setCookie("defaultmask","true");
  }  
  
  
  function init(){
  	var obj= document.getElementById("add_flag")
    obj.checked =getCookie("defaultmask")==null?false:true;
  }
  
  
    //检查
	 function checkChoose(obj){
       if(obj.checked){
       	  addCookie();
    	    $$("mask_bar").style.display="block";
    	    $$("mask_location").style.display="block";
       }else{
       	 delCookie('defaultmask');
    	   $$("mask_bar").style.display="none";
    	   $$("mask_location").style.display="none";
       }
	 }

	 function showMask(obj){
       if(obj.checked){
    	   $$("mask_src").style.display="block";
    	   $$("mask_location").style.display="block";
    	   $$("upload_btn").disabled=false;
       }
	 }

	 function hiddenMask(obj){
		 if(obj.checked){
	    	   $$("mask_src").style.display="none";;
	     }
      }


	 function select_class(o){
			//document.getElementById("upload_btn").disabled=true;
			if(o.value=="本地"){
				o.value="网络";
				document.getElementById("img_add").innerHTML="<input type=\"text\" id =\"upload_img_id\" name=\"upload_img\" style=\"width:210px;\" onkeyup=\"checkImag(this);\" />";
			}else if(o.value=="网络"){
				o.value="本地";
				document.getElementById("img_add").innerHTML="<input type=\"file\" id =\"upload_img_id\" name=\"upload_img\" style=\"width:220px;\" onchange=\"checkImag(this);\" />"
			}
			document.getElementById("upload_img_id").focus();
	  }

	  
//-->
</script>
</head>
<body  style="overflow:hidden;" onload="init()">
	<form name="form1" id="upload_form" method="post" enctype="multipart/form-data" target="upload_iframe">
		<input type="hidden" name="place" value="" />
		<input type="hidden" name="articleId" value="" />
		<input type="hidden" name="pictitle" value="" />
		<table>
         <tr align="left">
             <td colspan="2">
			   <input type="button" value="本地" onclick="select_class(this);" style="width:35px;" id="up_state" />
			   <span id="img_add">
			        <input type="file" id ="upload_img_id" name="upload_img" style="width:220px;" onchange="checkImag(this);" onkeyup="checkImag(this);" />
			   </span>
                                          加水印<input type="checkbox" id="add_flag" name="add_flag" onclick="checkChoose(this);"/>
			  </td>
        </tr>
        <tr><td colspan="2">(<font color="blue">图片大小限制为600K</font>)</td></tr>
        <tr id="mask_bar">
        	<td>默认水印<input type ="radio" name="operator_flag" value="1" onclick="hiddenMask(this)" checked/></td>
        	<td>新增水印<input type ="radio" name="operator_flag" value="2" onclick="showMask(this)"/></td>
        </tr>
        
        <tr align="left" id="mask_src" style="display:none">
         	<td  colspan="2">
	                               水印图：<input type="file" id ="upload_mask_id" name="upload_mask" style="width:220px;" onchange="checkImag(this);" onkeyup="checkImag(this);" />
         	         保存默认<input type="checkbox" id="default_mask" name="default_mask" />
         	</td>
        </tr>
        
        <tr align="left" id="mask_location">
            <td>水印位置：
				<select name="mask_local">
				  <option value ="1">顶部左</option>
				  <option value ="2">顶部中</option>
				  <option value="3">顶部右</option>
				  <option value="4">中部左</option>
                  <option value ="5">正中央</option>
				  <option value ="6">中部右</option>
				  <option value="7">底部左</option>
				  <option value="8">底部中</option>
                  <option value="9" selected="selected">底部右</option>
				</select>
			</td>
            <td>水印宽度：<input type="text" id="mask_width" name="mask_width" style="width:30px;"/>(<font color="red">整数</font>)</td>
        </tr>
        <tr align="center">
             <td><input type="button"  value="上传" style="width:50px;" id="upload_btn" onclick="up();" /></td>
        </tr>
		</table>
        <p id="message" style="margin:5px 0 0 0;color:#ff0000;"></p>
        <span id="file_name" style="display:none;"></span>
		<iframe width="0" height="0" style="display:none;" id="upload_iframe" name="upload_iframe" src=""></iframe>
	</form>
</body>

</html>